package controllers

import (
	"github.com/astaxie/beego"
	"log"
)

type DeviceInfoControllers struct {
	beego.Controller
}
var errorPage = "<h2>Internal request parameter error.</h2>"

type MqttConfig struct {
	broker string
	clientID string
}
type DeviceData struct {
	DeviceType uint8 `json:"type"`
	Temp float32 `json:"temp"`
	TempSet float32 `json:"tempset"`
	Speed uint `json:"speed"`
	SpeedSet uint `json:"speedset"`
	HourSet uint8 `json:"Hset"`
	MinSet uint8 `json:"Mset"`
	Hour uint8 `json:"Hour"`
	Min uint8 `json:"Min"`
	TempMin float32 `json:"tempmin"`
	TempMax float32 `json:"tempmax"`
	SpeedMin uint `json:"spmin"`
	SpeedMax uint `json:"spmax"`
	ErrorInfo uint16 `json:"errinfo"`
	State uint16 `json:"state"`
	Mode uint8 `json:"mode"`
	Memory uint8 `json:"memory"`
}
type Alarm struct {
	InnerSensorErr              uint `json:"inner_sensor_err"`
	InnerSensorTempAlarm        uint `json:"inner_sensor_temp_alarm"`
	ExternalSensorErr           uint `json:"external_sensor_err"`
	ExternalSensorOverTemp      uint `json:"external_sensor_over_temp"`
	MechanicalLimitTempOverTemp uint `json:"mechanical_limit_temp_over_temp"`
	MechanicalLimitSensorErr    uint `json:"mechanical_limit_sensor_err"`
	MotorStalling               uint `json:"motor_stalling"`
	ExternalSensorDrop          uint `json:"external_sensor_drop"`
	EndOfTime                   uint `json:"end_of_time"`
	ExternalSensorNotPlugged    uint `json:"external_sensor_not_plugged"`
}

// Get:  /deviceInfo?user_id=OPENID&geteway_id=GATEWAYID
func (d *DeviceInfoControllers) Get() {
	d.TplName = "deviceInfo.html"

	gatewayId := d.Input().Get("gateway_id")
	userid := d.Input().Get("user_id")
	d.Data["GatewayID"] = gatewayId
	d.Data["UserID"] = userid
	log.Printf("gatewayid is %s, userid is %s", gatewayId, userid)
	if gatewayId == "" || userid == ""{
		log.Printf("error: request args missing ")
		d.Ctx.WriteString(errorPage)
	}
}